/**
*
* @ author:cmd
* @ wechat:codercmd@qq.com
* @ data: 2020-03-05 15:14
*/
import front_door from './front_door';
import back_door from './back_door';

export default class door extends Laya.Script {
    /** @prop {name:name, tips:"提示文本", type:Node, default:null}*/
    owner_sprite:Laya.Sprite3D;

    front_door:Laya.Node = null;
    back_door:Laya.Node = null;

    door_time_count:number = 0;

    public front_open_flag:boolean = false;
    public back_open_flag:boolean  = false;
    public front_close_flag:boolean = false;
    public back_close_flag:boolean  = false;

    constructor() {super();}

    onAwake() {
        console.log('door');    
        this.owner.getChildByName('front').addComponent(front_door);  
        this.owner.getChildByName('back').addComponent(back_door);             
        this.owner_sprite = this.owner as Laya.Sprite3D;  
    }

    onUpdate(){
        this.door_time_count = this.door_time_count + Laya.timer.delta;

        if(this.door_time_count> 10)
        {
            this.door_time_count = 0;

            if(this.front_open_flag == true)
            {        
                this.owner_sprite.transform.localRotationEulerY = this.owner_sprite.transform.localRotationEulerY + 5;
                           
            } 
    
            if(this.front_close_flag == true)
            {
                if(this.owner_sprite.transform.localRotationEulerY >0)
                {
                    this.owner_sprite.transform.localRotationEulerY = this.owner_sprite.transform.localRotationEulerY - 1;
                }
                else
                {
                    this.owner_sprite.transform.localRotationEulerY = 0;
                    this.front_close_flag = false;
                }
            }
    
            if(this.back_open_flag == true)
            {           
                this.owner_sprite.transform.localRotationEulerY = this.owner_sprite.transform.localRotationEulerY - 5;
            }
    
            if(this.back_close_flag == true)
            {
                if(this.owner_sprite.transform.localRotationEulerY < 0)
                {
                    this.owner_sprite.transform.localRotationEulerY = this.owner_sprite.transform.localRotationEulerY + 1;
                }
                else
                {
                    this.owner_sprite.transform.localRotationEulerY = 0;
                    this.back_close_flag = false;
                }
            }

        }
       

        // if(this.front_flag == false || this.back_flag == false)
        // {
        //     if(this.owner_sprite.transform.localRotationEulerY >0)
        //     {
        //         this.owner_sprite.transform.localRotationEulerY = this.owner_sprite.transform.localRotationEulerY - 1;
        //     }
        //     else
        //     {
        //         this.owner_sprite.transform.localRotationEulerY = this.owner_sprite.transform.localRotationEulerY + 1; ;
        //     }
        // }
    }


}